﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using ACompany.OrderProcessing.Model;
using ACompany.OrderProcessing.Presentation.Customer;

public partial class Customer_CustomerList : System.Web.UI.UserControl, ICustomerListView
{
    private CustomerListPresenter _presenter;

    private void Page_Init(object sender, EventArgs e)
    {
        _presenter = new CustomerListPresenter(this);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            _presenter.Display();
    }

    public void ErrorMessage(string message)
    {
        if (string.IsNullOrEmpty(message))
        {
            pnlError.Visible = false;
            return;
        }
        pnlError.Visible = true;
        this.litErrorMessage.Text = message.Replace(Environment.NewLine, "<br/>");
    }

    public void InfoMessage(string message)
    {
        if (string.IsNullOrEmpty(message))
        {
            pnlInfo.Visible = false;
            return;
        }
        pnlInfo.Visible = true;
        this.litInfoMessage.Text = message.Replace(Environment.NewLine, "<br/>");
    }

    public void ViewTitle(string title)
    {

    }

    public List<Customer> Customers
    {
        set
        {
            this.grdCustomers.DataSource = value;
            this.grdCustomers.DataBind();
        }
    }
    protected void btnNewCustomer_Click(object sender, EventArgs e)
    {
        Response.Redirect("CustomerDetail.aspx?CustomerAction=Detail");
    }
    protected void grdCustomers_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
            case "deletecustomer":
                _presenter.RemoveCustomerBy(new Guid(e.CommandArgument.ToString()));
                break;
        }
    }
}